var app = new Vue({
    el: "#player",
    data: {
        // 查询关键字
        query: "",
        // 歌曲数组
        musicList: [],
        // 歌曲地址
        musicUrl: "",
        // 歌曲封面
        musicCover: "",
        // 歌曲评论
        hotComments: [],
        // 动画播放状态
        isPlaying: false,
        // 遮罩层的显示状态
        isShow: false,
        // mv地址
        mvUrl: ""
    },
    mounted(){
this.searchMusic1()
    },
    methods: {
        //初始歌单
        searchMusic1: function() {
            //初始化音量
            this.$refs.audio.volume=0.20
            this.$refs.video.volume=0.20
            var that = this;
            axios.get("https://autumnfish.cn/search?keywords=周杰伦" ).then(
                function(response) {
                    // console.log(response)
                    that.musicList = response.data.result.songs;           
                },
            );
        },

        // 歌曲搜索
        searchMusic: function() {
            var that = this;
            axios.get("https://autumnfish.cn/search?keywords=" + this.query).then(
                function(response) {
                    console.log(response);
                    that.musicList = response.data.result.songs;
                    // console.log(response.data.result.songs);
                },
                function(err) {}
            );
        },
        //获取当前要播放歌曲的信息
        getmusiclist(musicId){
            var that = this;
            // 获取歌曲地址
            axios.get("https://autumnfish.cn/song/url?id=" + musicId).then(
                function(response) {
                    // console.log(response);
                    // console.log(response.data.data[0].url);
                    that.musicUrl = response.data.data[0].url;
                },
                function(err) {}
            );

            // 歌曲详情获取
            axios.get("https://autumnfish.cn/song/detail?ids=" + musicId).then(
                function(response) {
                    // console.log(response);
                    that.musicCover = response.data.songs[0].al.picUrl;
                },
                function(err) {}
            );

            // 歌曲评论获取
            axios.get("https://autumnfish.cn/comment/hot?type=0&id=" + musicId).then(
                function(response) {
                    // console.log(response);
                    that.hotComments = response.data.hotComments;
                },
                function(err) {}
            );
        },
        // 歌曲播放
        playMusic: function(musicId) {
            this.musicUrl=""
            this.getmusiclist(musicId)
            this.isPlaying = true;
           
        },
        // 歌曲播放
        play: function() {
        this.isPlaying = true;
  
        },
        // 歌曲暂停
        pause: function() {
            // console.log("pause");
            this.isPlaying = false;
        },

        //点击控制音乐的播放和暂停
        stop(){
                if(this.musicUrl){
                    if(this.isPlaying){
                        this.$refs.audio.pause()
                    }else{
                        this.$refs.audio.play() 
                    }
                }else{
                    return
                }
        },
        // 播放mv
        playMV: function(mvId) {       
            this.$refs.audio.pause()
            this.$refs.video.controls=true
            var that = this;
            axios.get("https://autumnfish.cn/mv/url?id=" + mvId).then(
                function(response) {
                    // console.log(response);
                    // console.log(response.data.data.url);
                    that.isShow = true;
                   
                    that.mvUrl = response.data.data.url;
                },
            );
        },
        // 隐藏
        hide: function() {
            this.isShow = false;
           
            this.$refs.video.pause()
            this.$refs.video.controls=false
            if(this.musicUrl){
                this.$refs.audio.play()
            }else{
                return
            }
        }
    }
});